package com.laoyao.controller;

import com.jfinal.core.Controller;
import com.laoyao.beans.PageBean;
import com.laoyao.comm.config.CrossOrigin;
import com.laoyao.comm.model.Comment;
import com.laoyao.comm.model.CommentReply;
import com.laoyao.service.CommentService;
import com.laoyao.service.WordService;
import com.laoyao.util.DateUtil;

@CrossOrigin
public class CommentController extends Controller {
	public static String[] keywords = new String[] { "人渣",
			"混蛋", "操你妈", "操", "操你大爷的",
			"你大爷", "日", "日你大爷", "日你", "日你妹" };

	// 添加评论
	public void add() {

		Comment c = getBean(Comment.class, "");
		// 最好加一个不文明语言过滤
		// 最好在加一个发表评论间隔时间
		WordService w = new WordService(keywords);
		c.setContent(w.wordPass(c.getContent()));

		c.setTime(DateUtil.getTime());
		renderJson("success", c.save());
	}

	// 返回评论列表
	public void list() {
		PageBean p = getBean(PageBean.class, "");
		String id = getPara("id");
		renderJson("page",
				CommentService.me.list(p.getPageNumber(), p.getPageSize(), id));
	}

	// 回复
	public void reply() {
		CommentReply cp = getBean(CommentReply.class, "");
		// 最好加一个不文明语言过滤
		// 最好在加一个发表评论间隔时间
		cp.setTime(DateUtil.getTime());
		renderJson("success", cp.save());
	}

	// 回复列表
	public void replyList() {
		PageBean p = getBean(PageBean.class, "");
		String id = getPara("id");
		renderJson("page", CommentService.me.replyList(p.getPageNumber(),
				p.getPageSize(), id));
	}

}
